home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------------------------------------//
-
- // Synopsis: Dual vector with respect to Holder p-norm.
-
- // Syntax: dual ( X , p )
-
- // Description:
-
- // dual(X, p), where 1 <= p <= inf, is a vector of unit q-norm
- // that is dual to X with respect to the p-norm, that is, norm(Y,
- // q) = 1 where 1/p + 1/q = 1 and there is equality in the Holder
- // inequality: X'*Y = norm(X, p)norm(Y, q).
-
- // Special case: DUAL(X), where X >= 1 is a scalar, returns Y
- // such that 1/X + 1/Y = 1.
-
- // Called by PNORM.
-
- // This file is a translation of dual.m from version 2.0 of
- // "The Test Matrix Toolbox for Matlab", described in Numerical
- // Analysis Report No. 237, December 1993, by N. J. Higham.
-
- //-------------------------------------------------------------------//
-
- dual = function ( x , p )
- {
- local(p)
-
- if (max (size (x)) == 1 && nargs)
- {
- p = x;
- }
-
- // The following test avoids a `division by zero message' when p = 1.
-
- if (p == 1)
- {
- q = inf();
- else
- q = 1/(1-1/p);
- }
-
- if (max (size (x)) == 1 && nargs == 1)
- {
- y = q;
- return y;
- }
-
- if (norm (x,"i") == 0)
- {
- return x;
- }
-
- if (p == 1)
- {
- y = sign (x) + (x == 0); // y(i) = +1 or -1 (if x(i) real).
-
- else if (p == inf()) {
-
- xmax = max (abs (x));
- f = find (abs (x) == xmax);
- k = f[1];
- y = zeros (size (x));
- y[k] = sign(x[k]); // y is a multiple of unit vector e_k.
-
- else // 1 < p < inf. Dual is unique in this case.
-
- x = x/norm (x,"i"); // This scaling helps to avoid under/over-flow.
- y = abs(x).^(p-1) .* ( sign(x) + (x == 0) );
- y = y / norm (y, q); // Normalize to unit q-norm.
-
- } }
-
- return y;
- };
-